import {
  Controller,
  Post,
  Body,
  UseGuards,
  Request,
  Get,
  Delete,
  Put,
  Param,
  Query,
} from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { CreatePhoneDto } from './dto/create-phone.dto';
import { PhoneService } from './phone.service';
import { Phone } from './phone.entity';
import { RemovePhoneDto } from './dto/remove-phone.dto';
import { RetrievePhoneDto } from './dto/retrieve-phone.dto';
import { UpdatePhoneDto } from './dto/update-phone.dto';
import { FindPhoneDto } from './dto/find-phone.dto';
import { JwtAuthGuardUser } from 'src/auth/guards/jwt-auth.guard';

@ApiTags('手机授权')
@Controller('api/phone')
export class PhoneController {
  constructor(private readonly phoneService: PhoneService) {}

  // 增加
  // @UseGuards(JwtAuthGuardUser)
  @Post()
  @ApiOperation({ summary: '增加' })
  async create(@Body() createPhoneDto: CreatePhoneDto): Promise<Phone> {
    return await this.phoneService.create(createPhoneDto);
  }

  // 删除
  @UseGuards(JwtAuthGuardUser)
  @Delete()
  @ApiOperation({ summary: '删除' })
  async remove(@Body() removePhoneDto: RemovePhoneDto): Promise<any> {
    return await this.phoneService.delete(removePhoneDto);
  }

  // 更新
  @UseGuards(JwtAuthGuardUser)
  @Put(':id')
  @ApiOperation({ summary: '更新' })
  async update(
    @Param() params: RetrievePhoneDto,
    @Body() updatePhoneDto: UpdatePhoneDto,
  ): Promise<any> {
    return await this.phoneService.update({
      id: params.id,
      updatePhoneDto,
    });
  }

  // 列表
  // @UseGuards(JwtAuthGuard)
  @Get()
  @ApiOperation({ summary: '列表' })
  async findAll(@Query() query: FindPhoneDto): Promise<Phone> {
    return await this.phoneService.findAll(query);
  }

  // 根据 id 查找
  @Get(':id')
  @ApiOperation({ summary: '根据 id 查找' })
  async findOneById(@Param() params: RetrievePhoneDto): Promise<any> {
    return await this.phoneService.findOneById(params.id);
  }

  // 数量
  @Get('list/count')
  @ApiOperation({ summary: '用户数量' })
  async getCount(@Query() query: FindPhoneDto) {
    return await this.phoneService.getCount(query);
  }
}
